<?php

use yii\db\Schema;
use yii\db\Migration;

class m150212_062220_add_retarget_site_table extends Migration
{
    public function up()
    {
		$sql =<<<FINE

DROP TABLE IF EXISTS {{%condition_retarget}};
CREATE TABLE {{%condition_retarget}} (
  id int(11) unsigned NOT NULL AUTO_INCREMENT,
  solution_id int(11) unsigned NOT NULL,
  is_whitelist int(1) NOT NULL DEFAULT 0 COMMENT '0 blacklist, 1 whitelist, of no use for this condition',
  retarget_type_id int(11) COMMENT '重定向类型 id',
  retarget_site_id int(11) COMMENT '重定向标签',
  status int(1) NOT NULL DEFAULT 1 COMMENT '1 有效， 0 无效（删除或其他情况）',
  last_update timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS {{%retarget_site}};
CREATE TABLE {{%retarget_site}} (
  id int(11) unsigned NOT NULL AUTO_INCREMENT,
  tag varchar(128) COMMENT '重定向标签',
  url varchar(1024) NOT NULL COMMENT '重定向地址',
  retarget_type_id int(11) unsigned NOT NULL DEFAULT 1 COMMENT '重定向类型id',
  status int(1) NOT NULL DEFAULT 1 COMMENT '1 有效， 0 无效（删除或其他情况）',
  last_update timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

FINE;
		$this->execute($sql);
    }

    public function down()
    {
        $this->dropTable('{{%retarget_site}}');
    }
}
